﻿
using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;
using Dexter.DataTransferObject;
using Dexter.Dependency;
using Dexter.Services;

namespace Dexter.Web.Mvc.Helpers {
	public static class PinningHelper {
		public static MvcHtmlString CreatePinningMetas(this HtmlHelper helper, IEnumerable<PostDto> recentesPosts) {
			IUrlBuilder u = DexterContainer.Resolve <IUrlBuilder> ( );

			StringBuilder sb = new StringBuilder();

			sb.Append ( "if (window.external.msIsSiteMode()) {" );
			
			sb.Append ( "window.external.msSiteModeClearJumpList();" );

			sb.Append ( "window.external.msSiteModeCreateJumpList(\"Build My Pinned Site\");" );

			foreach ( var post in recentesPosts ) {
				sb.AppendFormat ( "window.external.msSiteModeAddJumpListItem('{0}', '{1}', \"{2}\", \"self\");", post.Title, u.Post.Detail ( post ), u.ResolveUrl ( "~/Images/bg-comments.ico" ) );
			}

			sb.Append ( "}" );

			return new MvcHtmlString ( sb.ToString() );
		}
	}
}
